<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>
<script>
    var list = [{
        name: "张三",
        class: "2217",
        chinese: 55,
        math: 66,
        english: 77,
    }, {
        name: "李四",
        class: "2217",
        chinese: 77,
        math: 86,
        english: 92,
    }, {
        name: "王五",
        class: "2215",
        chinese: 69,
        math: 94,
        english: 91,
    }, {
        name: "老刘",
        class: "2215",
        chinese: 91,
        math: 48,
        english: 76,
    }];



    // (1)  根据原数据得到一个新数组,包含每个人的姓名 班级 总分 (放到对象中)
    // var gradeList = list.map(function (item) { // item每一项数据
    //     var data = {};
    //     data.name = item.name;
    //     data.class = item.class;
    //     data.total = item.chinese + item.math + item.english;
    //     return data;
    // })
    // console.log(gradeList);

    // (2)  根据原数据得到一个新数组,找出2217班学员成绩
    var grade_2217 = list.filter(function (item) {
        return item.class === "2217";
    })
    console.log(grade_2217);


    // (3)  判断2217班是否存在语文不及格的成员
    // var flag = grade_2217.some(function (item) {
    //     return item.chinese < 60;
    // })
    // console.log(flag);


    // (4)  判断2217班所有成员是否数学都及格
    // var flag = grade_2217.every(function (item) {
    //     return item.math >= 60;
    // })
    // console.log(flag);


    // (5)  求2217班英语分数的平均值
    // var sum = grade_2217.reduce(function (prev, item) {
    //     console.log(item);
    //     return prev + item.english;
    // }, 0)
    // console.log(sum);
    // var avg = sum / grade_2217.length;
    // console.log(avg);

    // (6)将数据按总分 从高到低排序

    // list.sort(function (a, b) {
    //     console.log(a, b);
    //     return (b.chinese + b.math + b.english) - (a.chinese + a.math + a.english);
    // })
    // console.log(list);









</script>

</html>